<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="活动ID" prop="pressId">
        <el-input
          v-model="queryParams.pressId"
          placeholder="请输入活动ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="协会ID" prop="asId">
        <el-input
          v-model="queryParams.asId"
          placeholder="请输入协会ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="消息模板ID" prop="templateId">
        <el-input
          v-model="queryParams.templateId"
          placeholder="请输入消息模板ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="消息标题" prop="firstData">
        <el-input
          v-model="queryParams.firstData"
          placeholder="请输入消息标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色" prop="firstColor">
        <el-input
          v-model="queryParams.firstColor"
          placeholder="请输入颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="keyword1内容" prop="keyword1Data">
        <el-input
          v-model="queryParams.keyword1Data"
          placeholder="请输入keyword1内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色" prop="keyword1Color">
        <el-input
          v-model="queryParams.keyword1Color"
          placeholder="请输入颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="keyword2内容" prop="keyword2Data">
        <el-input
          v-model="queryParams.keyword2Data"
          placeholder="请输入keyword2内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色" prop="keyword2Color">
        <el-input
          v-model="queryParams.keyword2Color"
          placeholder="请输入颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="keyword3内容" prop="keyword3Data">
        <el-input
          v-model="queryParams.keyword3Data"
          placeholder="请输入keyword3内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色" prop="keyword3Color">
        <el-input
          v-model="queryParams.keyword3Color"
          placeholder="请输入颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="keyword4内容" prop="keyword4Data">
        <el-input
          v-model="queryParams.keyword4Data"
          placeholder="请输入keyword4内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色" prop="keyword4Color">
        <el-input
          v-model="queryParams.keyword4Color"
          placeholder="请输入颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="keyword5内容" prop="keyword5Data">
        <el-input
          v-model="queryParams.keyword5Data"
          placeholder="请输入keyword5内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色" prop="keyword5Color">
        <el-input
          v-model="queryParams.keyword5Color"
          placeholder="请输入颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="keyword6内容" prop="keyword6Data">
        <el-input
          v-model="queryParams.keyword6Data"
          placeholder="请输入keyword6内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色" prop="keyword6Color">
        <el-input
          v-model="queryParams.keyword6Color"
          placeholder="请输入颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="keyword7内容" prop="keyword7Data">
        <el-input
          v-model="queryParams.keyword7Data"
          placeholder="请输入keyword7内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色" prop="keyword7Color">
        <el-input
          v-model="queryParams.keyword7Color"
          placeholder="请输入颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="keyword8内容" prop="keyword8Data">
        <el-input
          v-model="queryParams.keyword8Data"
          placeholder="请输入keyword8内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色" prop="keyword8Color">
        <el-input
          v-model="queryParams.keyword8Color"
          placeholder="请输入颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="keyword9内容" prop="keyword9Data">
        <el-input
          v-model="queryParams.keyword9Data"
          placeholder="请输入keyword9内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色" prop="keyword9Color">
        <el-input
          v-model="queryParams.keyword9Color"
          placeholder="请输入颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色" prop="remarkColor">
        <el-input
          v-model="queryParams.remarkColor"
          placeholder="请输入颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否查看过" prop="isSee">
        <el-input
          v-model="queryParams.isSee"
          placeholder="请输入是否查看过"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['content:sendMessage:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['content:sendMessage:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['content:sendMessage:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['content:sendMessage:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sendMessageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="活动ID" align="center" prop="pressId" />
      <el-table-column label="类型 1 文章内容" align="center" prop="type" />
      <el-table-column label="协会ID" align="center" prop="asId" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="消息类型：0审批通知，1活动/会议提醒，2缴费通知，3会议通知A，4会议通知B" align="center" prop="templateType" />
      <el-table-column label="消息模板ID" align="center" prop="templateId" />
      <el-table-column label="消息标题" align="center" prop="firstData" />
      <el-table-column label="颜色" align="center" prop="firstColor" />
      <el-table-column label="keyword1内容" align="center" prop="keyword1Data" />
      <el-table-column label="颜色" align="center" prop="keyword1Color" />
      <el-table-column label="keyword2内容" align="center" prop="keyword2Data" />
      <el-table-column label="颜色" align="center" prop="keyword2Color" />
      <el-table-column label="keyword3内容" align="center" prop="keyword3Data" />
      <el-table-column label="颜色" align="center" prop="keyword3Color" />
      <el-table-column label="keyword4内容" align="center" prop="keyword4Data" />
      <el-table-column label="颜色" align="center" prop="keyword4Color" />
      <el-table-column label="keyword5内容" align="center" prop="keyword5Data" />
      <el-table-column label="颜色" align="center" prop="keyword5Color" />
      <el-table-column label="keyword6内容" align="center" prop="keyword6Data" />
      <el-table-column label="颜色" align="center" prop="keyword6Color" />
      <el-table-column label="keyword7内容" align="center" prop="keyword7Data" />
      <el-table-column label="颜色" align="center" prop="keyword7Color" />
      <el-table-column label="keyword8内容" align="center" prop="keyword8Data" />
      <el-table-column label="颜色" align="center" prop="keyword8Color" />
      <el-table-column label="keyword9内容" align="center" prop="keyword9Data" />
      <el-table-column label="颜色" align="center" prop="keyword9Color" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="颜色" align="center" prop="remarkColor" />
      <el-table-column label="跳转地址" align="center" prop="linkUrl" />
      <el-table-column label="接收消息的微信ID" align="center" prop="openids" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="是否查看过" align="center" prop="isSee" />
      <el-table-column label="微信用户ids" align="center" prop="wxUserIds" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['content:sendMessage:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['content:sendMessage:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改系统消息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="活动ID" prop="pressId">
          <el-input v-model="form.pressId" placeholder="请输入活动ID" />
        </el-form-item>
        <el-form-item label="协会ID" prop="asId">
          <el-input v-model="form.asId" placeholder="请输入协会ID" />
        </el-form-item>
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="消息模板ID" prop="templateId">
          <el-input v-model="form.templateId" placeholder="请输入消息模板ID" />
        </el-form-item>
        <el-form-item label="消息标题" prop="firstData">
          <el-input v-model="form.firstData" placeholder="请输入消息标题" />
        </el-form-item>
        <el-form-item label="颜色" prop="firstColor">
          <el-input v-model="form.firstColor" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="keyword1内容" prop="keyword1Data">
          <el-input v-model="form.keyword1Data" placeholder="请输入keyword1内容" />
        </el-form-item>
        <el-form-item label="颜色" prop="keyword1Color">
          <el-input v-model="form.keyword1Color" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="keyword2内容" prop="keyword2Data">
          <el-input v-model="form.keyword2Data" placeholder="请输入keyword2内容" />
        </el-form-item>
        <el-form-item label="颜色" prop="keyword2Color">
          <el-input v-model="form.keyword2Color" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="keyword3内容" prop="keyword3Data">
          <el-input v-model="form.keyword3Data" placeholder="请输入keyword3内容" />
        </el-form-item>
        <el-form-item label="颜色" prop="keyword3Color">
          <el-input v-model="form.keyword3Color" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="keyword4内容" prop="keyword4Data">
          <el-input v-model="form.keyword4Data" placeholder="请输入keyword4内容" />
        </el-form-item>
        <el-form-item label="颜色" prop="keyword4Color">
          <el-input v-model="form.keyword4Color" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="keyword5内容" prop="keyword5Data">
          <el-input v-model="form.keyword5Data" placeholder="请输入keyword5内容" />
        </el-form-item>
        <el-form-item label="颜色" prop="keyword5Color">
          <el-input v-model="form.keyword5Color" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="keyword6内容" prop="keyword6Data">
          <el-input v-model="form.keyword6Data" placeholder="请输入keyword6内容" />
        </el-form-item>
        <el-form-item label="颜色" prop="keyword6Color">
          <el-input v-model="form.keyword6Color" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="keyword7内容" prop="keyword7Data">
          <el-input v-model="form.keyword7Data" placeholder="请输入keyword7内容" />
        </el-form-item>
        <el-form-item label="颜色" prop="keyword7Color">
          <el-input v-model="form.keyword7Color" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="keyword8内容" prop="keyword8Data">
          <el-input v-model="form.keyword8Data" placeholder="请输入keyword8内容" />
        </el-form-item>
        <el-form-item label="颜色" prop="keyword8Color">
          <el-input v-model="form.keyword8Color" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="keyword9内容" prop="keyword9Data">
          <el-input v-model="form.keyword9Data" placeholder="请输入keyword9内容" />
        </el-form-item>
        <el-form-item label="颜色" prop="keyword9Color">
          <el-input v-model="form.keyword9Color" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="颜色" prop="remarkColor">
          <el-input v-model="form.remarkColor" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="跳转地址" prop="linkUrl">
          <el-input v-model="form.linkUrl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="接收消息的微信ID" prop="openids">
          <el-input v-model="form.openids" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否查看过" prop="isSee">
          <el-input v-model="form.isSee" placeholder="请输入是否查看过" />
        </el-form-item>
        <el-form-item label="微信用户ids" prop="wxUserIds">
          <el-input v-model="form.wxUserIds" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSendMessage, getSendMessage, delSendMessage, addSendMessage, updateSendMessage } from "@/api/content/sendMessage";

export default {
  name: "SendMessage",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 系统消息表格数据
      sendMessageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pressId: null,
        type: null,
        asId: null,
        userId: null,
        templateType: null,
        templateId: null,
        firstData: null,
        firstColor: null,
        keyword1Data: null,
        keyword1Color: null,
        keyword2Data: null,
        keyword2Color: null,
        keyword3Data: null,
        keyword3Color: null,
        keyword4Data: null,
        keyword4Color: null,
        keyword5Data: null,
        keyword5Color: null,
        keyword6Data: null,
        keyword6Color: null,
        keyword7Data: null,
        keyword7Color: null,
        keyword8Data: null,
        keyword8Color: null,
        keyword9Data: null,
        keyword9Color: null,
        remarkColor: null,
        linkUrl: null,
        openids: null,
        status: null,
        isSee: null,
        wxUserIds: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        pressId: [
          { required: true, message: "活动ID不能为空", trigger: "blur" }
        ],
        asId: [
          { required: true, message: "协会ID不能为空", trigger: "blur" }
        ],
        templateType: [
          { required: true, message: "消息类型：0审批通知，1活动/会议提醒，2缴费通知，3会议通知A，4会议通知B不能为空", trigger: "change" }
        ],
        templateId: [
          { required: true, message: "消息模板ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "修改时间不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询系统消息列表 */
    getList() {
      this.loading = true;
      listSendMessage(this.queryParams).then(response => {
        this.sendMessageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        pressId: null,
        type: null,
        asId: null,
        userId: null,
        templateType: null,
        templateId: null,
        firstData: null,
        firstColor: null,
        keyword1Data: null,
        keyword1Color: null,
        keyword2Data: null,
        keyword2Color: null,
        keyword3Data: null,
        keyword3Color: null,
        keyword4Data: null,
        keyword4Color: null,
        keyword5Data: null,
        keyword5Color: null,
        keyword6Data: null,
        keyword6Color: null,
        keyword7Data: null,
        keyword7Color: null,
        keyword8Data: null,
        keyword8Color: null,
        keyword9Data: null,
        keyword9Color: null,
        remark: null,
        remarkColor: null,
        linkUrl: null,
        openids: null,
        createTime: null,
        updateTime: null,
        status: 0,
        isSee: null,
        wxUserIds: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加系统消息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSendMessage(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改系统消息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSendMessage(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSendMessage(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除系统消息编号为"' + ids + '"的数据项？').then(function() {
        return delSendMessage(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('content/sendMessage/export', {
        ...this.queryParams
      }, `sendMessage_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
